/// <reference name="MicrosoftAjax.js" />
/// <reference name="AjaxDataControls.Common.Common.js" assembly="AjaxDataControls" />

Type.registerNamespace('AjaxDataControls');

$ADC.GridViewCommandColumn = function()
{
	/// <summary>
	/// Represents a special column that displays command buttons to perform selecting, editing, or deleting operations in a GridView control.
	/// </summary>

	// Default button for Edit/Cancel/Delete/Update
	this._buttonType = $ADC.GridViewColumnButtonType.Link;
	// Default button for Select/Select All
	this._selectButtonType = $ADC.GridViewColumnSelectButtonType.CheckBox;
	// Cancel
	this._cancelImageUrl = '';
	this._cancelText = 'Cancel';
	this._showCancelButton = true;
	// Delete
	this._deleteImageUrl = '';
	this._deleteText = 'Delete';
	this._showDeleteButton = false;
	// Edit
	this._editImageUrl = '';
	this._editText = 'Edit';
	this._showEditButton = false; // Show for the Edit and Update buttons
	// Update
	this._updateImageUrl = '';
	this._updateText = 'Update';
	// Select
	this._selectImageUrl = '';
	this._selectText = 'Select';
	this._showSelectButton = false;
	// Select All (checkbox)
	this._selectAllImageUrl = '';
	this._selectAllText = 'Select all';
	this._showSelectAllButton = false;

	// Arrays for button instances and handlers								       
	this._cancelButtons = new Array();
	this._cancelClickHandlers = new Array();

	this._deleteButtons = new Array();
	this._deleteClickHandlers = new Array();

	this._editButtons = new Array();
	this._editClickHandlers = new Array();

	this._selectButtons = new Array();
	this._selectClickHandlers = new Array();

	this._updateButtons = new Array();
	this._updateClickHandlers = new Array();

	// 'Select All' button instance and handler
	this._selectAllButton = null;
	this._selectAllClickHandler = null;

	// CheckBox Counter for the ID
	this._checkBoxCounter = 0;

	$ADC.GridViewCommandColumn.initializeBase(this);
	$ADC.GridViewCommandColumn.callBaseMethod(this, 'set_allowDragAndDrop', [false]);
}

/// CheckBox Format for the ID
///  - '/GridView/Columns/GridViewCommandColumn.js' to set the ID for the created button.
///  - '/GridView/GridView.js' to find the button to 'Select All'.
$ADC.GridViewCommandColumn.CheckBoxIDFormat = "gv{0}:row{1}:chk";

$ADC.GridViewCommandColumn.prototype =
{
	get_buttonType: function()
	{
		/// <value type="AjaxDataControls.GridViewColumnButtonType">
		/// Use this property to specify which type of button is displayed in a GridViewCommandColumn.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._buttonType;
	},

	set_buttonType: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: $ADC.GridViewColumnButtonType}]);
		if (e) throw e;

		if (this._buttonType != value)
		{
			this._buttonType = value;
			this.raisePropertyChanged('buttonType');
		}
	},

	get_selectButtonType: function()
	{
		/// <value type="AjaxDataControls.GridViewColumnButtonType">
		/// Use this property to specify which type of Select button is displayed in a GridViewCommandColumn.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._selectButtonType;
	},

	set_selectButtonType: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: $ADC.GridViewColumnSelectButtonType}]);
		if (e) throw e;

		if (this._selectButtonType != value)
		{
			this._selectButtonType = value;
			this.raisePropertyChanged('selectButtonType');
		}
	},

	get_cancelImageUrl: function()
	{
		/// <value type="String">
		/// Use this property to specify the image to display for the Cancel button. This image can be in any file format (.jpg, .gif, .bmp, and so on), as long as the client's browser supports that format.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._cancelImageUrl;
	},

	set_cancelImageUrl: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
		if (e) throw e;

		if (this._cancelImageUrl != value)
		{
			this._cancelImageUrl = value;
			this.raisePropertyChanged('cancelImageUrl');
		}
	},

	get_cancelText: function()
	{
		/// <value type="String">
		/// Use this property to specify the text to display for the Cancel button.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._cancelText;
	},

	set_cancelText: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
		if (e) throw e;

		if (this._cancelText != value)
		{
			this._cancelText = value;
			this.raisePropertyChanged('cancelText');
		}
	},

	get_deleteImageUrl: function()
	{
		/// <value type="String">
		/// Use this property to specify the image to display for the Delete button. This image can be in any file format (.jpg, .gif, .bmp, and so on), as long as the client's browser supports that format.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._deleteImageUrl;
	},

	set_deleteImageUrl: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
		if (e) throw e;

		if (this._deleteImageUrl != value)
		{
			this._deleteImageUrl = value;
			this.raisePropertyChanged('deleteImageUrl');
		}
	},

	get_deleteText: function()
	{
		/// <value type="String">
		/// Use this property to specify the text to display for the Delete button.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._deleteText;
	},

	set_deleteText: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
		if (e) throw e;

		if (this._deleteText != value)
		{
			this._deleteText = value;
			this.raisePropertyChanged('deleteText');
		}
	},

	get_editImageUrl: function()
	{
		/// <value type="String">
		/// Use this property to specify the image to display for the Edit button. This image can be in any file format (.jpg, .gif, .bmp, and so on), as long as the client's browser supports that format.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._editImageUrl;
	},

	set_editImageUrl: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
		if (e) throw e;

		if (this._editImageUrl != value)
		{
			this._editImageUrl = value;
			this.raisePropertyChanged('editImageUrl');
		}
	},

	get_editText: function()
	{
		/// <value type="String">
		/// Use this property to specify the text to display for the Edit button.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._editText;
	},

	set_editText: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
		if (e) throw e;

		if (this._editText != value)
		{
			this._editText = value;
			this.raisePropertyChanged('editText');
		}
	},

	get_updateImageUrl: function()
	{
		/// <value type="String">
		/// Use this property to specify the image to display for the Update button. This image can be in any file format (.jpg, .gif, .bmp, and so on), as long as the client's browser supports that format.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._updateImageUrl;
	},

	set_updateImageUrl: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
		if (e) throw e;

		if (this._updateImageUrl != value)
		{
			this._updateImageUrl = value;
			this.raisePropertyChanged('updateImageUrl');
		}
	},

	get_updateText: function()
	{
		/// <value type="String">
		/// Use this property to specify the text to display for the Update button.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._updateText;
	},

	set_updateText: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
		if (e) throw e;

		if (this._updateText != value)
		{
			this._updateText = value;
			this.raisePropertyChanged('updateText');
		}
	},

	get_selectImageUrl: function()
	{
		/// <value type="String">
		/// Use this property to specify the image to display for the Select button. This image can be in any file format (.jpg, .gif, .bmp, and so on), as long as the client's browser supports that format.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._selectImageUrl;
	},

	set_selectImageUrl: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
		if (e) throw e;

		if (this._selectImageUrl != value)
		{
			this._selectImageUrl = value;
			this.raisePropertyChanged('selectImageUrl');
		}
	},

	get_selectText: function()
	{
		/// <value type="String">
		/// Use this property to specify the text to display for the Select button.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._selectText;
	},

	set_selectText: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
		if (e) throw e;

		if (this._selectText != value)
		{
			this._selectText = value;
			this.raisePropertyChanged('selectText');
		}
	},

	get_selectAllImageUrl: function()
	{
		/// <value type="String">
		/// Use this property to specify the image to display for the Select All button on the header. This image can be in any file format (.jpg, .gif, .bmp, and so on), as long as the client's browser supports that format.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._selectAllImageUrl;
	},

	set_selectAllImageUrl: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
		if (e) throw e;

		if (this._selectAllImageUrl != value)
		{
			this._selectAllImageUrl = value;
			this.raisePropertyChanged('selectAllImageUrl');
		}
	},

	get_selectAllText: function()
	{
		/// <value type="String">
		/// Use this property to specify the text to display for the Select All button on the header.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._selectAllText;
	},

	set_selectAllText: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: String}]);
		if (e) throw e;

		if (this._selectAllText != value)
		{
			this._selectAllText = value;
			this.raisePropertyChanged('selectAllText');
		}
	},

	get_showCancelButton: function()
	{
		/// <value type="Boolean">
		/// Whether a Cancel button is displayed in a GridViewCommandColumn.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._showCancelButton;
	},

	set_showCancelButton: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: Boolean}]);
		if (e) throw e;

		if (this._showCancelButton != value)
		{
			this._showCancelButton = value;
			this.raisePropertyChanged('showCancelButton');
		}
	},

	get_showDeleteButton: function()
	{
		/// <value type="Boolean">
		/// Whether a Delete button is displayed in a GridViewCommandColumn.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._showDeleteButton;
	},

	set_showDeleteButton: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: Boolean}]);
		if (e) throw e;

		if (this._showDeleteButton != value)
		{
			this._showDeleteButton = value;
			this.raisePropertyChanged('showDeleteButton');
		}
	},

	get_showEditButton: function()
	{
		/// <value type="Boolean">
		/// Whether a Edit button is displayed in a GridViewCommandColumn.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._showEditButton;
	},

	set_showEditButton: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: Boolean}]);
		if (e) throw e;

		if (this._showEditButton != value)
		{
			this._showEditButton = value;
			this.raisePropertyChanged('showEditButton');
		}
	},

	get_showSelectButton: function()
	{
		/// <value type="Boolean">
		/// Whether a Select button is displayed in a GridViewCommandColumn.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._showSelectButton;
	},

	set_showSelectButton: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: Boolean}]);
		if (e) throw e;

		if (this._showSelectButton != value)
		{
			this._showSelectButton = value;
			this.raisePropertyChanged('showSelectButton');
		}
	},

	get_showSelectAllButton: function()
	{
		/// <value type="Boolean">
		/// Whether a Select All button is displayed in a GridViewCommandColumn.
		/// </value>
		if (arguments.length !== 0) throw Error.parameterCount();

		return this._showSelectAllButton;
	},

	set_showSelectAllButton: function(value)
	{
		var e = Function._validateParams(arguments, [{ name: 'value', type: Boolean}]);
		if (e) throw e;

		if (this._showSelectAllButton != value)
		{
			this._showSelectAllButton = value;
			this.raisePropertyChanged('showSelectAllButton');
		}
	},

	initialize: function()
	{
		/// <summary>
		/// Initialize the column.
		/// </summary>        
		$ADC.GridViewCommandColumn.callBaseMethod(this, 'initialize');
	},

	dispose: function()
	{
		/// <summary>
		/// Dispose the column.
		/// </summary>
		$ADC.GridViewCommandColumn.callBaseMethod(this, 'dispose');

		delete this._cancelButtons;
		delete this._cancelClickHandlers;

		delete this._deleteButtons;
		delete this._deleteClickHandlers;

		delete this._editButtons;
		delete this._editClickHandlers;

		delete this._selectButtons;
		delete this._selectClickHandlers;

		delete this._updateButtons;
		delete this._updateClickHandlers;

		delete this._selectAllButton;
		delete this._selectAllClickHandler;
	},

	_selectAllClicked: function(e, context)
	{
		// Is the GridView instanced ?
		if (context.sender)
		{
			var gridView = context.sender;
			var rowLength = gridView.get_rows().length;
			if (rowLength == 0)
				return;

			gridView.selectAllRows((gridView.get_selectedIndexes().length < rowLength));
		}
	},

	renderHeader: function(row)
	{
		/// <summary>
		/// Draws the header section in the previously specified header container. You will only override this method if you
		/// want to develop custom colum which requires extra logic. Other than this you do not have to call this method in your code.
		/// </summary>
		/// <param name="row" type="AjaxDataControls.GridViewRow">
		/// The GridViewRow which is passed to render the header that item type is set to <b>AjaxDataControls.GridViewRowType.Header</b>.
		/// </param>

		var e = Function._validateParams(arguments, [{ name: 'row', type: $ADC.GridViewRow}]);
		if (e) throw e;

		var owner = this.get_owner();
		var container = this.get_headerContainer();

		if (owner == null)
		{
			throw Error.invalidOperation('Owner must be set before calling this method.');
		}
		if (container == null)
		{
			throw Error.invalidOperation('Header container must be set before calling this method.');
		}

		var addSpace = false;

		// Show Select All button ?
		if (this.get_showSelectAllButton())
		{
			// Use '-1' to ID to find this element after when it's necessary.
			this._checkBoxCounter = -1;

			// Create DOM element.
			var button = this._createButton(this.get_selectButtonType(), this.get_selectAllText(), this.get_selectAllImageUrl(), this.get_controlStyle(), owner.SelectCommandName, row.get_rowIndex());

			addSpace = true;
			container.appendChild(button);  // Insert the DOM element into the cell.

			clickHandler = $ADC.Util.addCallbackEventHandler(button, 'click', this._selectAllClicked, { sender: owner, row: row });

			// Add the DOM element and handler to a local variable and keep them alive.
			this._selectAllButton = button;
			this._selectAllClickHandler = clickHandler;
		}

		var headerText = this.get_headerText();
		var sortField = this.get_sortField();

		// Does it add Sort anchor on the header column text ?
		if ((!$ADC.Util.isEmptyString(headerText)) && (!$ADC.Util.isEmptyString(sortField)))
		{
			// Does it add a blank-space after the new element ? 
			if (addSpace)
			{
				container.appendChild(document.createTextNode(' '));
			}

			// Add a Sort anchor to the header column text.
			this._sortLink = document.createElement('a');
			this._sortLink.appendChild(document.createTextNode(headerText));
			this._sortLink.href = 'javascript:void(0)';
			container.appendChild(this._sortLink); // Add the anchor to the cell.

			var sortColumn = owner.get_sortColumn();
			var sortOrder = $ADC.GridViewSortOrder.Ascending;
			// Is this current column the Sort Field ?
			if (sortColumn == sortField)
			{
				var sortImageUrl = '';
				if (owner.get_sortOrder() == $ADC.GridViewSortOrder.Ascending)
				{
					sortOrder = $ADC.GridViewSortOrder.Descending;
					sortImageUrl = owner.get_sortOrderAscendingImageUrl();
				}
				else
				{
					sortImageUrl = owner.get_sortOrderDescendingImageUrl();
				}

				if (!$ADC.Util.isEmptyString(sortImageUrl))
				{
					var img = document.createElement('img');
					img.setAttribute('src', sortImageUrl);
					img.setAttribute('alt', '');
					container.appendChild(img);
				}
			}

			// Create a callback to pass the sortColumn name and direction
			this._sortHandler = $ADC.Util.addCallbackEventHandler(this._sortLink, 'click', owner._raiseSort, { sender: owner, sortColumn: sortField, sortOrder: sortOrder });
		}
		else if ($ADC.Util.isEmptyString(headerText)) // Does it the header column text blank ?
		{
			headerText = ' ';  // Default value.
		}

		// Does it add a blank-space after the header text ? 
		if (addSpace)
		{
			container.appendChild(document.createTextNode(' '));
		}

		// Add the header text to the cell.
		container.appendChild(document.createTextNode(headerText));

		if (this.get_headerStyle() != null)
		{
			this.get_headerStyle().apply(container);
		}

		if (this._isDragAndDropAllowed())
		{
			container.style.cursor = 'move';
			container.style.zIndex = '9999';
		}
	},

	renderData: function(dataRow, row, container)
	{
		/// <summary>
		/// This method is used to render the data cell. You do not have to call this method in your code.
		/// </summary>
		/// <param name="dataRow" type="Object">
		/// The item of the GridView dataSource.
		/// </param>
		/// <param name="row" type="AjaxDataControls.GridViewRow">
		/// The GridViewRow which is passed to render the column data cell.
		/// </param>
		/// <param name="container" domElement="true">
		/// The container cell(td) to render the data of this column.
		/// </param>
		var e = Function._validateParams(arguments, [{ name: 'dataRow', type: Object }, { name: 'row', type: $ADC.GridViewRow }, { name: 'container', type: Object}]);
		if (e) throw e;

		var owner = this.get_owner();
		if (owner == null)
		{
			throw Error.invalidOperation('Owner must be set before calling this method.');
		}

		var buttonType = this.get_buttonType();
		var controlStyle = this.get_controlStyle();
		var button;
		var clickHandler;

		// Which type of GridViewRow is being created ?
		if ((row.get_rowType() == $ADC.GridViewRowType.EditRow))
		{
			// Show Update button ?	(Update because the row is in Edit mode)
			if (this.get_showEditButton() == true)
			{
				// Create DOM element.
				button = this._createButton(buttonType, this.get_updateText(), this.get_updateImageUrl(), controlStyle, owner.UpdateCommandName, row.get_rowIndex());

				container.appendChild(button); // Insert the DOM element into the cell.

				clickHandler = this._addCallbackCommand(button, owner, row);

				// Add the DOM element and handler to an array and keep them alive.
				Array.add(this._updateButtons, button);
				Array.add(this._updateClickHandlers, clickHandler);
			}

			// Show Cancel button?
			if (this.get_showCancelButton() == true)
			{
				// Create DOM element for the Cancel button.
				button = this._createButton(buttonType, this.get_cancelText(), this.get_cancelImageUrl(), controlStyle, owner.CancelCommandName, row.get_rowIndex());

				container.appendChild(document.createTextNode(' ')); // Add a blank-space to the end of the DOM element.
				container.appendChild(button); // Insert the DOM element into the cell.

				clickHandler = this._addCallbackCommand(button, owner, row);

				// Add the DOM element and handler to an array and keep them alive.
				Array.add(this._cancelButtons, button);
				Array.add(this._cancelClickHandlers, clickHandler);
			}
		}
		else // GridViewRowType.Row || GridViewRowType.AlternatingRow
		{
			var addSpace = false;
			// Show Select button ?
			if (this.get_showSelectButton() == true)
			{
				// Create DOM element for the Select button.
				button = this._createButton(this.get_selectButtonType(), this.get_selectText(), this.get_selectImageUrl(), controlStyle, owner.SelectCommandName, row.get_rowIndex());

				container.appendChild(button); // Insert the DOM element into the cell.

				clickHandler = this._addCallbackCommand(button, owner, row);

				// Add the DOM element and handler to an array and keep them alive.
				Array.add(this._selectButtons, button);
				Array.add(this._selectClickHandlers, clickHandler);

				addSpace = true;
			}
			// Show Edit button ? 
			if (this.get_showEditButton() == true)
			{
				// Create DOM element for the Edit button.
				button = this._createButton(buttonType, this.get_editText(), this.get_editImageUrl(), controlStyle, owner.EditCommandName, row.get_rowIndex());

				// Does it add a blank-space to the end ?
				if (addSpace)
				{
					container.appendChild(document.createTextNode(' '));
				}
				container.appendChild(button); // Insert the DOM element into the cell.

				clickHandler = this._addCallbackCommand(button, owner, row);

				// Add the DOM element and handler to an array and keep them alive.
				Array.add(this._editButtons, button);
				Array.add(this._editClickHandlers, clickHandler);

				addSpace = true;
			}
			// Show Delete button ?
			if (this.get_showDeleteButton() == true)
			{
				// Create DOM element for the Delete button.
				button = this._createButton(buttonType, this.get_deleteText(), this.get_deleteImageUrl(), controlStyle, owner.DeleteCommandName, row.get_rowIndex());

				// Does it add a blank-space to the end ?
				if (addSpace)
				{
					container.appendChild(document.createTextNode(' '));
				}

				container.appendChild(button);   // Insert the DOM element into the cell.

				clickHandler = this._addCallbackCommand(button, owner, row);

				// Add the DOM element and handler to an array and keep them alive.
				Array.add(this._deleteButtons, button);
				Array.add(this._deleteClickHandlers, clickHandler);
			}
		}

		if (this.get_itemStyle() != null)
		{
			this.get_itemStyle().apply(container);
		}
	},

	_addCallbackCommand: function(element, owner, row)
	{
		return $ADC.Util.addCallbackEventHandler(element, 'click', owner._raiseCommand, { sender: owner, row: row });
	},

	releaseResource: function()
	{
		/// <summary>
		/// Releases all resources which are associated with this column.
		/// </summary>

		$ADC.GridViewCommandColumn.callBaseMethod(this, 'releaseResource');

		var i = 0;

		if ((this._cancelButtons.length > 0) && (this._cancelClickHandlers.length > 0))
		{
			for (i = this._cancelButtons.length - 1; i > -1; i--)
			{
				$removeHandler(this._cancelButtons[i], 'click', this._cancelClickHandlers[i]);
				delete this._cancelButtons[i];
				delete this._cancelClickHandlers[i];
			}
		}

		Array.clear(this._cancelButtons);
		Array.clear(this._cancelClickHandlers);

		if ((this._deleteButtons.length > 0) && (this._deleteClickHandlers.length > 0))
		{
			for (i = this._deleteButtons.length - 1; i > -1; i--)
			{
				$removeHandler(this._deleteButtons[i], 'click', this._deleteClickHandlers[i]);
				delete this._deleteButtons[i];
				delete this._deleteClickHandlers[i];
			}
		}

		Array.clear(this._deleteButtons);
		Array.clear(this._deleteClickHandlers);

		if ((this._editButtons.length > 0) && (this._editClickHandlers.length > 0))
		{
			for (i = this._editButtons.length - 1; i > -1; i--)
			{
				$removeHandler(this._editButtons[i], 'click', this._editClickHandlers[i]);
				delete this._editButtons[i];
				delete this._editClickHandlers[i];
			}
		}

		Array.clear(this._editButtons);
		Array.clear(this._editClickHandlers);

		if ((this._selectButtons.length > 0) && (this._selectClickHandlers.length > 0))
		{
			for (i = this._selectButtons.length - 1; i > -1; i--)
			{
				$removeHandler(this._selectButtons[i], 'click', this._selectClickHandlers[i]);
				delete this._selectButtons[i];
				delete this._selectClickHandlers[i];
			}
		}

		Array.clear(this._selectButtons);
		Array.clear(this._selectClickHandlers);

		if ((this._updateButtons.length > 0) && (this._updateClickHandlers.length > 0))
		{
			for (i = this._updateButtons.length - 1; i > -1; i--)
			{
				$removeHandler(this._updateButtons[i], 'click', this._updateClickHandlers[i]);
				delete this._updateButtons[i];
				delete this._updateClickHandlers[i];
			}
		}

		Array.clear(this._updateButtons);
		Array.clear(this._updateClickHandlers);
	},

	_createButton: function(buttonType, text, imageUrl, style, commandName, rowIndex)
	{
		if ($ADC.Util.isEmptyString(text))
		{
			text = '';
		}

		if ($ADC.Util.isEmptyString(imageUrl))
		{
			imageUrl = '';
		}

		var button;

		if ((buttonType == $ADC.GridViewColumnButtonType.Link) || (buttonType == $ADC.GridViewColumnSelectButtonType.Link))
		{
			button = document.createElement('a');
			button.appendChild(document.createTextNode(text));
			button.setAttribute('href', 'javascript:void(0)');
		}
		else if ((buttonType == $ADC.GridViewColumnButtonType.Image) || (buttonType == $ADC.GridViewColumnSelectButtonType.Image))
		{
			button = document.createElement('img');
			button.setAttribute('alt', text);
			button.setAttribute('title', text);

			if ((imageUrl != null) && (imageUrl.length > 0))
			{
				button.setAttribute('src', imageUrl);
			}

			button.style.cursor = 'pointer';
		}
		else if ((buttonType == $ADC.GridViewColumnButtonType.Button) || (buttonType == $ADC.GridViewColumnSelectButtonType.Button))
		{
			button = document.createElement('input');
			button.setAttribute('type', 'button');
			button.setAttribute('value', text);
		}
		// Only for SelectButton - GridViewColumnSelectButtonType.CheckBox
		else if ((buttonType == $ADC.GridViewColumnSelectButtonType.CheckBox))
		{
			button = document.createElement('input');
			button.setAttribute('type', 'checkbox');
			button.setAttribute('id', String.format($ADC.GridViewCommandColumn.CheckBoxIDFormat, this.get_owner().get_id(), this._checkBoxCounter++));
		}

		if (style != null)
		{
			style.apply(button);
		}

		button.commandName = commandName;
		button.commandArgument = rowIndex;

		return button;
	}
}

$ADC.GridViewCommandColumn.registerClass('AjaxDataControls.GridViewCommandColumn', $ADC.GridViewBaseColumn);

if (typeof (Sys) != 'undefined')
{
	Sys.Application.notifyScriptLoaded();
}